package group.itk.vuelogintestbackend.login.shiro

import org.apache.shiro.authc.AuthenticationInfo
import org.apache.shiro.authc.AuthenticationToken
import org.apache.shiro.authc.SimpleAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken
import org.apache.shiro.authz.AuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo
import org.apache.shiro.crypto.hash.Md5Hash
import org.apache.shiro.realm.AuthorizingRealm
import org.apache.shiro.subject.PrincipalCollection

class UserRealm : AuthorizingRealm() {

    override fun doGetAuthenticationInfo(token: AuthenticationToken?): AuthenticationInfo? {
        token as UsernamePasswordToken

        if(token.username != "admin"){
            return null
        }

        return SimpleAuthenticationInfo("","admin","")
    }

    override fun doGetAuthorizationInfo(principals: PrincipalCollection?): AuthorizationInfo {
        return SimpleAuthorizationInfo().apply {
            roles = setOf("user")
        }
    }
}
